<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>frequencies</title>
</head>

<body>
    <script>
        const frequencies = arr =>
            arr.reduce((a, v) => ((a[v] = a[v] ? a[v] + 1 : 1), a), {});
        console.log(frequencies(['a', 'b', 'a', 'c', 'a', 'a', 'b']));
        console.log(frequencies([...'ball']));
    </script>
</body>

</html>